package com.dewei.ling.ballsapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dewei.ling.ballsapp.R;
import com.dewei.ling.ballsapp.bean.HotData;
import com.dewei.ling.ballsapp.utils.PicassoUtils;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by jet on 2018-10-12.
 */

public class HotAdapter extends BaseAdapter {
    private Context mContext;
    private List<HotData> mList;
    private LayoutInflater inflater;
    private HotData data;
    private WindowManager windowManager;
    private int width;
    public HotAdapter(Context mContext , List<HotData> mList){
        this.mContext = mContext;
        this.mList = mList;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //get系统服务
        windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        //获取屏幕宽度
        width = windowManager.getDefaultDisplay().getWidth();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_hot,null);

            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_source = convertView.findViewById(R.id.tv_source);
            viewHolder.tv_tag = convertView.findViewById(R.id.tv_tag);
            viewHolder.tv_time = convertView.findViewById(R.id.tv_time);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        data = mList.get(position);

        viewHolder.tv_title.setText(data.getJijin_title());
        viewHolder.tv_source.setText(data.getLabel());
        viewHolder.tv_time.setText(data.getSdate());
        viewHolder.tv_tag.setText(data.getTag());



        return convertView;
    }

    class ViewHolder{

        private TextView tv_title;
        private TextView tv_source;
        private TextView tv_time;
        private TextView tv_tag;
    }
}
